package com.strom.reflection;

import com.google.common.base.Throwables;
import com.google.common.reflect.Invokable;
import com.google.common.reflect.Reflection;
import com.strom.pojo.Foo;
import com.strom.pojo.IFoo;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class ReflectionDemo {

    public static void main(String[] args) {
        // Throwables.
        try {
            Class clazz =  Class.forName("com.strom.pojo.Foo");
            Foo foo = (Foo) clazz.newInstance();

            Method method = clazz.getMethod("hello");
            Invokable invokable = Invokable.from(method);
            System.out.println(invokable);
            System.out.println(invokable.isPrivate());
            System.out.println(invokable.getReturnType());
            Object[] objects = new Object[]{};
            invokable.invoke(foo, objects);

            // ==========
            IFoo iFoo =  Reflection.newProxy(IFoo.class, (m, n, j) -> j[0]);
            System.out.println(iFoo.hello("hello"));
            Reflection.initialize(IFoo.class);
            System.out.println(Reflection.getPackageName(IFoo.class));
        } catch (Exception e) {
            e.printStackTrace();
        }



        // Reflection.newProxy()
    }
}
